﻿namespace HySoft.Cash.Structure
{
    using System;
    using System.Data;
    using HiLand.Utility.DataBase;

    public class TorginfoDT
    {
        public static TorginfoDT ConvertFrom(DataRow row)
        {
            TorginfoDT entity = new TorginfoDT();
            if (row != null)
            {
                entity.AgreementDate = Convert.ToDateTime(row["AgreementDate"]);
                entity.OrgName = Convert.ToString(row["OrgName"]);
                entity.TradingName = Convert.ToString(row["TradingName"]);
                entity.ABN = Convert.ToString(row["ABN"]);
                entity.Industry = Convert.ToString(row["Industry"]);
                entity.OfficeAddress = Convert.ToString(row["OfficeAddress"]);
                entity.WebSite = Convert.ToString(row["WebSite"]);
                entity.ContactPerson = Convert.ToString(row["ContactPerson"]);
                entity.sPosition = Convert.ToString(row["sPosition"]);
                entity.ExpCreditLimit = Convert.ToDecimal(row["ExpCreditLimit"]);
                entity.PostalAddress = Convert.ToString(row["PostalAddress"]);
                entity.ContactPhone1 = Convert.ToString(row["ContactPhone1"]);
                entity.ContactPhone2 = Convert.ToString(row["ContactPhone2"]);
                entity.Fax = Convert.ToString(row["Fax"]);
                entity.Mobile = Convert.ToString(row["Mobile"]);
                entity.PreferredEmail = Convert.ToString(row["PreferredEmail"]);
                entity.AltEmail1 = Convert.ToString(row["AltEmail1"]);
                entity.AltEmail2 = Convert.ToString(row["AltEmail2"]);
                entity.UserName = Convert.ToString(row["UserName"]);
                entity.PassWord = Convert.ToString(row["PassWord"]);
                entity.RegDate = Convert.ToDateTime(row["RegDate"]);
                entity.IsValid = (OrginfoStatuses)Convert.ToInt32(row["IsValid"]);
                entity.CreditLimit = Convert.ToDecimal(row["CreditLimit"]);
                entity.FeeBalance = Convert.ToDecimal(row["FeeBalance"]);
                if (DataRowHelper.IsExistField(row, "AvailableBalance") && Convert.IsDBNull("AvailableBalance") == false)
                {
                    entity.AvailableBalance = Convert.ToDecimal(row["AvailableBalance"]);
                }
                entity.Sid = Convert.ToInt32(row["Sid"]);

                if (Convert.IsDBNull(row["RemainBalance"]) == false)
                {
                    entity.RemainBalance = Convert.ToDecimal(row["RemainBalance"]);
                }

                if (Convert.IsDBNull(row["CreditBalance"]) == false)
                {
                    entity.CreditBalance = Convert.ToDecimal(row["CreditBalance"]);
                }
            }

            return entity;
        }

        public string ABN;
        public DateTime AgreementDate;
        public static string allFields = "Sid,AgreementDate,OrgName,TradingName,ABN,Industry,OfficeAddress,WebSite,ContactPerson,sPosition,ExpCreditLimit,PostalAddress,ContactPhone1,ContactPhone2,Fax,Mobile,PreferredEmail,AltEmail1,AltEmail2,UserName,PassWord,RegDate,IsValid,CreditLimit,FeeBalance,CreditBalance,(CreditLimit - CreditBalance) as AvailableBalance,RemainBalance";
        public string AltEmail1;
        public string AltEmail2;
       
        public string ContactPerson;
        public string ContactPhone1;
        public string ContactPhone2;
        public decimal ExpCreditLimit;
        public decimal CreditLimit;
        public decimal FeeBalance;
        public decimal CreditBalance;
        public decimal AvailableBalance;
        public decimal RemainBalance;
        public string Fax;
        public string Industry;
        public OrginfoStatuses IsValid;
        public string Mobile;
        public string OfficeAddress;
        public string OrgName;
        public string PassWord;
        public string PostalAddress;
        public string PreferredEmail;
        public DateTime RegDate;
        public int Sid;
        public string sPosition;
        public string TradingName;
        public string UserName;
        public string WebSite;
        
    }

    /// <summary>
    /// 企业用户IsValid的状态
    /// </summary>
    public enum OrginfoStatuses
    {
        UnNormal = 0,
        Normal = 1,
    }

    /// <summary>
    /// 企业用户是否已经被管理员获知
    /// </summary>
    public enum OrgInfoKnowns
    { 
        UnKnown=0,
        Known=1,
    }
}

